package com.concurrency.example.aqs;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 测试TwinsLock
 * 预计两两输出
 */
public class TwinsLockTest {

    public static void main(String[] args) {
        final Lock lock = new TwinsLock();
        class Worker extends Thread {
            public void run() {
                    lock.lock();
                    try {
                        SleepUtils.second(2);
                        System.out.println(Thread.currentThread().getName());
                    } finally {
                        lock.unlock();
                    }
            }
        }
        // 启动10个线程
        for (int i = 0; i < 10; i++) {
           new Worker().start();
        }
    }
}
